package com.px.user.entity;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.px.user.model.ActionModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.Generated;
import org.hibernate.annotations.GenerationTime;

import javax.persistence.*;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Null;
import java.math.BigDecimal;
import java.sql.Timestamp;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Entity(name = "charge_money")
@org.hibernate.annotations.Table(appliesTo = "charge_money", comment = "充值记录表")
public class ChargeMoney {

    @Id
    @NotNull(groups = {ActionModel.Update.class})
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Null(groups = {ActionModel.Insert.class}, message = "删除id字段")
    @Column(unique = true, nullable = false, columnDefinition = "bigint comment '主键'")
    private Long id;

    @ApiModelProperty(value = "用户ID", example = "1")
    @Column(columnDefinition = "bigint comment '用户ID'")
    private Long userId;

    @NotNull(groups = {ActionModel.Insert.class})
    @Null(groups = {ActionModel.Update.class})
    @ApiModelProperty(value = "充值金额(500倍数)", example = "500")
    @Column(columnDefinition = "decimal(12,2) comment '充值金额'")
    private BigDecimal money;

    @ApiModelProperty(value = "充值状态: CHARGING#充值中,CHARGING_FAIL#充值失败,SUCCESS#成功,FAIL#失败", example = "ing")
    @Column(columnDefinition = "varchar(64) comment '充值状态: CHARGING#充值中,CHARGING_FAIL#充值失败,SUCCESS#成功,FAIL#失败'")
    private String status;

    @ApiModelProperty(value = "充值渠道: 支付宝,微信,云闪付,银联,人工", example = "@不提交")
    @Column(columnDefinition = "varchar(16) comment '充值渠道: 支付宝,微信,云闪付,银联,人工'")
    private String channel;

    @NotBlank(groups = {ActionModel.Insert.class})
    @ApiModelProperty(value = "备注", example = "必须提交")
    @Column(columnDefinition = "varchar(512) comment '备注'")
    private String remark;

    @Generated(GenerationTime.INSERT)
    @ApiModelProperty(value = "创建时间", hidden = true)
    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @Column(columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP comment '创建时间'", insertable = false, updatable = false)
    private Timestamp createTime;

    @Generated(GenerationTime.INSERT)
    @ApiModelProperty(value = "更新时间", hidden = true)
    @JsonProperty(access = JsonProperty.Access.WRITE_ONLY)
    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @Column(columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP comment '更新时间'", insertable = false, updatable = false)
    private Timestamp updateTime;

    /**
     * 扩展字段
     */
    @Transient
    @JsonProperty(access = JsonProperty.Access.READ_ONLY)
    @ApiModelProperty(value = "昵称", example = "@不提交", hidden = true)
    private String nickname;

    /**
     * 扩展查询字段
     */
    @Transient
    @JsonIgnore
    @ApiModelProperty(value = "查询开始时间", hidden = true)
    private Timestamp startTime;

    @Transient
    @JsonIgnore
    @ApiModelProperty(value = "查询结束时间", hidden = true)
    private Timestamp endTime;

    @Transient
    @JsonIgnore
    @ApiModelProperty(value = "查询排序字段", hidden = true)
    private String orderField;

    @Transient
    @JsonIgnore
    @ApiModelProperty(value = "查询开始索引", hidden = true)
    private Integer startIndex;

    @Transient
    @JsonIgnore
    @ApiModelProperty(value = "查询返回数量", hidden = true)
    private Integer limit;

    @ApiModelProperty(value = "支付渠道编号", example = "07")
    @Column(columnDefinition = "varchar(10) comment '支付渠道编号'")
    public String channelNo;

    @ApiModelProperty(value = "支付方式", example = "如：支付宝 或者 微信")
    @Column(columnDefinition = "varchar(20) comment '支付方式'")
    public String paymentType;
}
